import { stringify } from 'qs';
import request from '../utils/request';
import { ipConfig } from './config';

const basePath = ipConfig.baseServerName();

const proUrls = {
  checkRecord: `${basePath}/checkCord/getECHistory`, // 设备点巡检历史记录查询、搜索
  createTask: `${basePath}/checkCord/createCheckTask`, // 设备点巡检任务创建
  getTaskInfo: `${basePath}/checkCord/findDetail?checkrecordId=`, // 点巡检任务详情接口
  finishTask: `${basePath}/checkCord/finishCheckTask?checkrecordId=`, // 结束巡检任务
};

export const checkRecord = async params => {
  const url = `${ipConfig.url(proUrls.checkRecord)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};

export const createTask = async params => {
  const url = `${ipConfig.url(proUrls.createTask)}`;
  return request(url, {
    method: 'POST',
    body: params,
  }).then();
};

export const getTaskInfo = async params => {
  const url = `${ipConfig.url(proUrls.getTaskInfo)}${params}`;
  return request(url, {
    method: 'GET',
  }).then();
};

export const finishTask = async params => {
  const url = `${ipConfig.url(proUrls.finishTask)}${params}`;
  return request(url, {
    method: 'GET',
  }).then();
};
